<?php
$_menu_sidebar='';
foreach($children as $one){
    $_one_url=$this->createUrl('cate/list',array('pid'=>$one->pid,'cid'=>$one->cid));

    $_menu["$one->name"]=$_one_url;


    if($one->cid==15){
        $cs=Yii::app()->clientScript;
        $cs->registerScriptFile(Yii::app()->request->baseUrl.'/js/change.js',CClientScript::POS_HEAD );

        if($one->pid==$current->pid && $one->cid==$current->cid){
            $_menu_sidebar.='<li id="cid-sub" class="m"><span class="first"></span><a href="'.$_one_url.'">'.$one->name.'</a></li>';
        }else{
            $_menu_sidebar.='<li id="cid-sub" ><span></span><a href="'.$_one_url.'">'.$one->name.'</a></li>';
        }

        $aid=Yii::app()->request->getParam('aid',0);
        $criteria=new CDbCriteria;
        $criteria->condition='status=1';
        $av=Adviser::model()->findAll($criteria);
        $av_html='';
        if(!empty($av)){
            foreach($av as $av_one){
                $av_html.='<li'.(($aid==$av_one->id)?' class="x"':'').'><span></span><a href="'.
                    $this->createUrl('cate/list',array('pid'=>1, 'cid'=>15, 'aid'=>$av_one->id)).'">'.$av_one->username.'</a></li>';
            }
            $_menu_sidebar .= '<li style="display: block;" id="id-sub" class="sub"><ul class="sub-leftmenu">'.$av_html.'</ul></li>';
        }

    }else{
        if($one->pid==$current->pid && $one->cid==$current->cid){
            $_menu_sidebar.='<li class="m"><span class="first"></span><a href="'.$_one_url.'">'.$one->name.'</a></li>';
        }else{
            $_menu_sidebar.='<li><span></span><a href="'.$_one_url.'">'.$one->name.'</a></li>';
        }
    }
}

$this->pageTitle=Yii::app()->name . ' - '.$current->parent->name;

$this->breadcrumbs=$_menu;
$link=array(
    $current->parent->name=>$this->createUrl('cate/list',array('pid'=>$current->pid)),
    $current->name =>$this->createUrl('cate/list',array('pid'=>$current->pid, 'cid'=>$current->cid))
);

if($cid==19 || $cid==20 || $cid==21){
    $aid=Yii::app()->request->getParam('aid', 0);

    $criteria = new CDbCriteria;
    $criteria->order='aid DESC';
    $criteria->condition='type=4 AND cid=19';
    $a_ls=Article::model()->findAll($criteria);
    $a_li='';
    if(!empty($a_ls)) foreach($a_ls as $a_one){
        if($a_one->grade==0){
            $a_one_link='<a href="'.$this->createUrl('cate/list',array('pid'=>3, 'cid'=>19, 'aid'=>$a_one->aid)).
                '">'.$a_one->title.'</a>';
        }elseif($a_one->grade==1){
            $a_one_link='<a target="_blank" href="'.$a_one->excerpt.'">'.$a_one->title.'</a>';
        }
        $a_li .= '<li'.(($cid==19&&$aid==$a_one->aid)?' class="x"':'').'><span></span>'.$a_one_link.'</li>';

        if($aid == $a_one->aid){
            $link[$a_one->title]='';
        }
    }

    $cs=Yii::app()->clientScript;
    $cs->registerScriptFile(Yii::app()->request->baseUrl.'/js/change.js',CClientScript::POS_HEAD );

    $_menu_sidebar='<li id="cid-sub" class="cursor'.($cid==19?' m':'').'"><span'.(($cid==19)?' class="first"':'').'></span><a href="'.
        $this->createUrl('cate/list',array('pid'=>3, 'cid'=>19)).'">理事会成员</a></li>
        <li style="display: block;" id="id-sub" class="sub">
            <ul class="sub-leftmenu">'.$a_li.'
            </ul>
        </li>
	<li id="cid-sub-1" class="cursor'.($cid==20?' m':'').'"><span'.(($cid==20)?' class="first"':'').'></span>团体单位会员</li>
	<li style="display: block;" id="id-sub-1" class="sub">
	<ul class="sub-leftmenu">
		<li'.(($cid==20&&$type==1)?' class="x"':'').'><span></span><a href="'.
        $this->createUrl('cate/list',array('pid'=>3, 'cid'=>20, 'type'=>1)).'">公共机构</a></li>
		<li'.(($cid==20&&$type==2)?' class="x"':'').'><span></span><a href="'.
        $this->createUrl('cate/list',array('pid'=>3, 'cid'=>20, 'type'=>2)).'">学校教育</a></li>
		<li'.(($cid==20&&$type==3)?' class="x"':'').'><span></span><a href="'.
        $this->createUrl('cate/list',array('pid'=>3, 'cid'=>20, 'type'=>3)).'">公司企业</a></li>
		<li'.(($cid==20&&$type==4)?' class="x"':'').'><span></span><a href="'.
        $this->createUrl('cate/list',array('pid'=>3, 'cid'=>20, 'type'=>4)).'">其他团体</a></li>
	</ul>
		</li>
		<li id="cid-sub-2" class="cursor'.($cid==21?' m':'').'"><span'.(($cid==21)?' class="first"':'').'></span>个人会员</li>
		<li style="" id="id-sub-2" class="sub">
	<ul class="sub-leftmenu">
		<li'.(($cid==21&&$type==1)?' class="x"':'').'><span></span><a href="'.
        $this->createUrl('cate/list',array('pid'=>3, 'cid'=>21, 'type'=>1)).'">尊最会员</a></li>
		<li'.(($cid==21&&$type==2)?' class="x"':'').'><span></span><a href="'.
        $this->createUrl('cate/list',array('pid'=>3, 'cid'=>21, 'type'=>2)).'">高级会员</a></li>
		<li'.(($cid==21&&$type==3)?' class="x"':'').'><span></span><a href="'.
        $this->createUrl('cate/list',array('pid'=>3, 'cid'=>21, 'type'=>3)).'">普善会员</a></li>
		<li'.(($cid==21&&$type==4)?' class="x"':'').'><span></span><a href="'.
        $this->createUrl('cate/list',array('pid'=>3, 'cid'=>21, 'type'=>4)).'">晋学会员</a></li>
	</ul>
	</li>';


if($cid==20){
    if($type == 1){
        $link['公共机构']='';
    }
    if($type == 2){
        $link['学校教育']='';
    }
    if($type == 3){
        $link['公司企业']='';
    }
    if($type == 4){
        $link['其他团体']='';
    }
}

if($cid==21){
    if($type == 1){
        $link['尊最会员']='';
    }
    if($type == 2){
        $link['高级会员']='';
    }
    if($type == 3){
        $link['普善会员']='';
    }
    if($type == 4){
        $link['晋学会员']='';
    }
}

}elseif(in_array($cid, array(22,23,24,25,26,27))){
    $this->breadcrumbs='';
    $this->renderPartial('no_menu',array(
        'cid'=>$cid,
        'current'=>$current,
    ));
    return;
}
?>
<div class="subpageContainer">
    <div class="left">
        <!--标题-->
        <div class="k-title sub-title">
            <div class="l"><?php echo $current->parent->name; ?></div>
            <div class="r"></div>
        </div>
        <!--列表内容-->
        <div class="subpage-left-content">
            <ul class="leftmenu black">
                <?php echo $_menu_sidebar; ?>
            </ul>
        </div>
        <!--底部圆角-->
        <div class="k-fot sub-fot"> <span class="fotright"></span> </div>
        <!--圆角结束-->
    </div>
    <div class="right">
        <div class="detailContent-title">
            <?php if(isset($this->breadcrumbs)):?>
                <?php
                $this->widget('zii.widgets.CBreadcrumbs', array(
                'htmlOptions'=>array('class'=>'local'),
                'separator'=>'&nbsp;&gt;&nbsp;',
                'links'=>$link,
                'homeLink'=>'当前位置：首页',
                'tagName'=>'span',
            )); ?><!-- breadcrumbs -->
            <?php endif?>
        </div>
            <?php
            if($cid==10){
                echo $this->renderPartial('item/10', array(
                    'article'=> Article::model()->find('cid=10'),
                ));
            }else if($cid==11){
                echo $this->renderPartial('item/11', array(
                    'articles'=> Article::model()->findAll('cid=11 AND enabled=1 ORDER BY sort ASC, createtime DESC'),
                ));
            }else if($cid==12){
                echo $this->renderPartial('item/12', array(
                    'article'=> Article::model()->find('cid=12 AND enabled=1'),
                ));
            }else if($cid==13){
                $criteria=new CDbCriteria;
                $criteria->condition='`enabled`=1 AND cid=13';
                $criteria->order='`sort` ASC, `createtime` DESC';
                $dataProvider=new CActiveDataProvider('Article',array(
                    'criteria'=>$criteria,
                    'pagination'=>array(
                        'pageSize'=>5,
                    ),
                ));
                echo '<div class="detailContent"><h4>'.$current->name.'</h4>';
                $this->widget('zii.widgets.CListView', array(
                    'dataProvider'=>$dataProvider,
                    'itemView'=>'item/13',
                    'ajaxUpdate'=>false,
                    'itemsTagName'=>'ul',
                    'itemsCssClass'=>'shortContent',
                ));
                echo '</ul></div>';
            }else if($cid==14){
                $criteria=new CDbCriteria;
//                $criteria->condition='`p`.`type_pg` = 1 AND `p`.`type_p_vasn`=1';
                $criteria->with='info';
                $criteria->condition='`info`.`manager` = 1 AND `t`.`status`=1';
                $criteria->with=array('p','info');
                $users=Users::model()->findAll($criteria);

                echo $this->renderPartial('item/14', array(
                    'users'=> $users,
                ));
            }else if($cid==15){
                $one_adviser = Adviser::model()->find(array('condition'=>'status=1'));

                $aid=Yii::app()->request->getParam('aid',isset($one_adviser->id) ? $one_adviser->id : 0);
                $criteria=new CDbCriteria;
                $criteria->condition='status=1 AND id=:aid';
                $criteria->params=array(':aid'=>$aid);

                $av=Adviser::model()->find($criteria);

                echo $this->renderPartial('item/'.$cid, array(
                    'user'=> $av,
                ));
            }else if($cid==16 || $cid==17 || $cid==18){
                echo $this->renderPartial('item/16', array(
                    'articles'=> Article::model()->findAll('cid='.$cid.' AND enabled=1'),
                ));

                $criteria=new CDbCriteria;
                $criteria->condition='`enabled`=1 AND cid='.$cid;
                $criteria->order='`sort` ASC, `createtime` DESC';
                $dataProvider=new CActiveDataProvider('Article',array(
                    'criteria'=>$criteria,
                    'pagination'=>array(
                        'pageSize'=>16,
                    ),
                ));

                $session=new CHttpSession();
                $session->open();
                $session['i']=1;

                echo '<div class="articleListwarp"><ul class="articleList">';
                $this->widget('zii.widgets.CListView', array(
                    'dataProvider'=>$dataProvider,
                    'itemView'=>'item/16',
                    'ajaxUpdate'=>false,
                ));
                echo '</ul></div>';
            }else if($cid==19 || $cid==20 || $cid==21){
                $aid=Yii::app()->request->getParam('aid', 0);

                if($type==0 && $cid!=19){
                    echo '<div class="wp">请选择子分类</div>';
                    return;
                }elseif($aid>0){
                    $article=Article::model()->findByPk($aid);
                    echo '<div class="wp">';
                    if(empty($article)){
                        echo '没有找到此内容';
                    }else{
                        echo $article->content;
                    }
                    echo '</div></div>';
                    return;
                }
                $criteria=new CDbCriteria;
                if($cid==19){
                    $criteria->with='info';
                    $criteria->condition='`info`.`director` = 1';
//                    $users=Users::model()->with('info')->findAll($criteria);
                }else if($cid==20 && in_array($type, array(1,2,3,4))){
                    $criteria->with='p';
                    $criteria->condition='`p`.`type_pg` = 2 AND `p`.`type_g_pebg`='.$type.' AND `p`.`open`=1';
//                    $users=Users::model()->with('p')->findAll($criteria);
                }else if($cid==21 && in_array($type, array(1,2,3,4))){
                    $criteria->with='p';
                    $criteria->condition='`p`.`type_pg` = 1 AND `p`.`type_p_vasn`='.$type.' AND `p`.`open`=1';
//                    $users=Users::model()->with('p')->findAll($criteria);
                }
                $dataProvider=new CActiveDataProvider('Users',array(
                    'criteria'=>$criteria,
                    'pagination'=>array(
                        'pageSize'=>54,
                    ),
                ));

                if($cid==19||$cid==20){
                    $itemView='item/19';
                    $ul_class='listCon';
                }else{
                    $itemView='item/21';
                    $ul_class='listCon memberList';
                }

                $session=new CHttpSession();
                $session->open();
                $session['i']=1;

                echo '
<style type="text/css">
    .list-view .items li {
        border-bottom: 0;
    }
</style>
                <div class="wp"><ul class="'.$ul_class.'">';
                $this->widget('zii.widgets.CListView', array(
                    'dataProvider'=>$dataProvider,
                    'itemView'=>$itemView,
                    'ajaxUpdate'=>false,
                    'template'=>"{items}\n{pager}"
                ));
                echo '</ul></div>';

            } else {

            }
            ?>
    </div>
    <div class="clear"></div>
</div>
